<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/vue.js"></script>
</head>
<body>
<div id="app">
    <div>
        <input type="text" v-model="value" placeholder="添加ToDo">
        <button @click="add">Add</button>
    </div>
    <h1>正在进行中</h1>
    <ul>
        <li v-for="(item,index) of start">
            <input type="checkbox" v-model='item.state'>
            <input type="text" v-model="item.title">
        </li>
    </ul>
    <h1>已完成</h1>
    <ul>
        <li v-for="(item,index) of end">
            <input type="checkbox" v-model='item.state'>
            <input type="text" v-model="item.title">
        </li>
    </ul>
</div>
<script>
    const vm = new Vue({
        el:'#app',
        data:{
            list:[{
                title:'学习Vue.js',
                state:false
            },{
                title:'学习Html',
                state:true
            }],
            value:''
        },
        computed:{
            start(){
                let arr = []
                this.list.forEach(item=>{
                    if (item.state==false){
                        arr.push(item)
                    }
                })
                console.log(arr)
                return arr
            },
            end(){
                let arr = []
                this.list.forEach(item=>{
                    if (item.state){
                        arr.push(item)
                    }
                })
                return arr
            }
        },
        watch:{
            // value(newValue,oldValue){
            //     console.log('监听到了',newValue)
            //     console.log(oldValue)
            // }
        },
        methods:{
            add(){
                this.list.push({title:this.value,state:false})
                console.log(this.value)
                this.value = ''
            }
        }
    })
</script>
</body>
</html>